﻿using System;
using System.Collections.Generic;

namespace Infrastructure.CrossCutting.IoC
{
    /// <summary>
    /// IoCFactory  implementation 
    /// </summary>
    public static class IoCFactory
    {
       
        #region Members

        static IContainer _currentContainer = null;
        static IIoCFactory _currentIoCFactory = null;

        #endregion

        #region Public Methods
        /// <summary>
        /// Get current configured IContainer
        /// <remarks>
        /// At this moment only IoCUnityContainer existss
        /// </remarks>
        /// </summary>
        public static IContainer CurrentContainer
        {
            get
            {
                return _currentContainer ?? (_currentContainer = _currentIoCFactory.Create());
            }
        }
        /// <summary>
        /// Set the IoC factory to use
        /// </summary>
        public static void SetCurrent(IIoCFactory ioCFactory)
        {
            _currentIoCFactory = ioCFactory;
            _currentContainer = null;
        }

        public static IContainer GetContainer()
        {
            return _currentContainer ?? (_currentContainer = _currentIoCFactory.Create());
        }

        #endregion
    }
}
